package com.dongnam.quanly.common.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.dongnam.quanly.common.model.ChiTietDonHang;
import com.dongnam.quanly.common.model.ChiTietPhieuNhapXuat;
import com.dongnam.quanly.common.model.compkey.ChiTietPhieuNhapXuatId;
import com.dongnam.quanly.common.persistence.HibernateUtil;

public class ChiTietPhieuNhapXuatDao extends ExtendedGenericDao<ChiTietPhieuNhapXuat, ChiTietPhieuNhapXuatId> {
	public List<Object[]> getChiTietPhieuNhapXuatByDonHang(String sodonhang) {

		Query query = getSession()
				.createQuery(
						"Select c.maVthh,sum(c.soLuong),c.productName,c.phieuNhapXuat from ChiTietPhieuNhapXuat c , PhieuNhapXuat p "
								+ "where c.phieuNhapXuat= p.soChungTu and p.donHang=:sodonhang GROUP BY c.maVthh ORDER BY c.maVthh")
				.setParameter("sodonhang", sodonhang);
		@SuppressWarnings("unchecked")
		List<Object[]> list = query.list();
		return list;

	}

	public List<ChiTietPhieuNhapXuat> getListChiTietPNXBySoPhieu(String sophieu) {

		String queryString = "Select ctpnx from ChiTietPhieuNhapXuat ctpnx where ctpnx.phieuNhapXuat=:sophieu order by ctpnx.maVthh";
		Query query = getSession().createQuery(queryString);

		query.setParameter("sophieu", sophieu);

		@SuppressWarnings("unchecked")
		List<ChiTietPhieuNhapXuat> list = query.list();
		return list;

	}

}
